package demo9;

class Method {
    public int val;
}
public class Test {
    //使用方法来交换两个数的值
    public static void swap(Method m1,Method m2){
        int tmp =  m1.val;
        m1.val = m2.val;
        m2.val = tmp;
    }
    public static void main(String[] args) {
        Method method1 = new Method();
        Method method2 = new Method();

        method1.val = 20;
        method2.val = 30;

        System.out.println("交换前："+"method1:"+method1.val+" method2:"+method2.val);
        swap(method1,method2);
        System.out.println("交换后："+"method1:"+method1.val+" method2:"+method2.val);
    }
}
